package com.umeng.analytics.pro;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

public class an extends y {
    private static final String a = "uuid";
    private Context b;
    private String c;
    private String d;
    private static final String e = "yosuid";
    private static final String f = "23346339";

    public an(Context arg3) {
        super("uuid");
        this.b = null;
        this.c = null;
        this.d = null;
        this.b = arg3;
        this.c = null;
        this.d = null;
    }

    public static String a(String arg5, String arg6) {
        String v0_2;
        try {
            return (String) Class.forName("android.os.SystemProperties").getMethod("get", String.class, String.class).invoke(null, arg5, arg6);
        } catch (Exception v0) {
            v0.printStackTrace();
            v0_2 = arg6;
        }

        return v0_2;
    }

    private String b(String arg8) {
        BufferedReader v3_2;
        BufferedReader v2_1 = null;
        Throwable v6;
        String v1_5;
        URLConnection v4;
        InputStream v2;
        DataOutputStream v1_1;
        URLConnection v1_2;
        InputStream is;
        DataOutputStream dos = null;
        int v1;
        HttpsURLConnection conn = null;
        InputStream v3 = null;
        this.d = an.a("ro.yunos.openuuid", "");
        if (!TextUtils.isEmpty(this.d)) {
            String v0 = this.d;
            return v0;
        }

        this.c = an.a("ro.aliyun.clouduuid", "");
        if (TextUtils.isEmpty(this.c)) {
            this.c = an.a("ro.sys.aliyun.clouduuid", "");
        }

        if (TextUtils.isEmpty(this.c)) {
            return this.d;
        }

        try {
            conn = (HttpsURLConnection) new URL("https://cmnsguider.yunos.com:443/genDeviceToken").openConnection();
            v1 = 30000;
            conn.setConnectTimeout(v1);
            conn.setReadTimeout(30000);
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setHostnameVerifier(new HostnameVerifier() {
                public boolean verify(String arg3, SSLSession arg4) {
                    return new BrowserCompatHostnameVerifier().verify("cmnsguider.yunos.com", arg4);
                }
            });
            v1_5 = "appKey=" + URLEncoder.encode("23338940", "UTF-8") + "&uuid=" + URLEncoder.encode("FC1FE84794417B1BEF276234F6FB4E63", "UTF-8");
            dos = new DataOutputStream(conn.getOutputStream());
            dos.writeBytes(v1_5);
            dos.flush();
            if (conn.getResponseCode() != 200) {

            } else {
                is = conn.getInputStream();
                v2_1 = new BufferedReader(new InputStreamReader(is));
                StringBuffer v1_6 = new StringBuffer();
                while (true) {
                    String v3_1 = v2_1.readLine();
                    if (v3_1 == null) {
                        break;
                    }
                    v1_6.append(v3_1);
                }
                this.d = v1_6.toString();
                v3 = is;
            }
        } catch (Exception v1_4) {
            try {
                dos.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            if (v2_1 != null) {
                try {
                    v2_1.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }

            if (v3 != null) {
                try {
                    v3.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }

            if (conn != null) {
                conn.disconnect();
            }
        }
        return this.d;
    }

    public String f() {
        try {
            if (TextUtils.isEmpty(an.a("ro.yunos.version", ""))) {
                return null;
            }

            if (this.b == null) {
                return null;
            }

            SharedPreferences v1 = ba.a(this.b);
            if (v1 == null) {
                return null;
            }

            String v0_1 = v1.getString("yosuid", "");
            if (!TextUtils.isEmpty(((CharSequence) v0_1))) {
                return v0_1;
            }

            this.d = this.b("23346339");
            if (!TextUtils.isEmpty(this.d) && this.b != null && v1 != null) {
                SharedPreferences.Editor v0_2 = v1.edit();
                if (v0_2 != null) {
                    v0_2.putString("yosuid", this.d).commit();
                }
            }

            return this.d;
        } catch (Exception v0) {
            v0.printStackTrace();
        }

        return null;
    }
}

